Imports System.Data.SqlClient
Imports AVLProject.DeclaracionesFunciones
Imports AVLProject.GPSDevice

Imports System.Console
Imports System.IO.TextReader
Imports System.IO
Imports System.Net
Imports System.IO.Ports
Imports System.Text
Imports System.Xml
Imports System.IO.FileStream


Imports System.Threading
Imports System.Collections


Public Class GPSNmeaFile

    Private WithEvents SerialPort As New IO.Ports.SerialPort
    Dim LogSerialPort As New StreamWriter("C:\nmea0183.txt", True)


    Public Function GrabarRegistroFile() As Boolean   ' A QUIE HAY QUE PONER LA PILA 

        Dim GPS As New GPSDevice ' NO ES NECESATIO 

        Dim PilaDataGPS As Stack = GPS.ReadData(PortCOM)

        For i As Integer = 0 To PilaDataGPS.Count - 1   'DE AQUI PARA ABAJO

            Dim DatoGPS As String = PilaDataGPS.Pop()
            LogSerialPort.Write(DatoGPS & vbCrLf)

            If DatoGPS.Substring(0, 6) = "$GPRMC" Then

                Me.GrabarRegistroDataBase(DatoGPS)

            End If

        Next

        PilaDataGPS.Clear()

    End Function


    Public Function GrabarRegistroDataBase(ByVal DatoGPS As String) As Boolean

        Dim FieldsDataGPS() As String = Split(DatoGPS, ",")

        Dim Mobil1 As Integer = IDMovil
        Dim Fecha As String = FieldsDataGPS(9)
        Dim Hora As String = FieldsDataGPS(1)
        Dim Latitud As String = FieldsDataGPS(3)
        Dim Longitud As String = FieldsDataGPS(5)
        Dim Velocidad As String = FieldsDataGPS(7)
        Dim Rumbo As String = FieldsDataGPS(8)

        Dim Validate As String = FieldsDataGPS(2)   ' A VALIDO ' V INVALIDO
        Dim HemisphereNS As String = FieldsDataGPS(4)
        Dim HemisphereEW As String = FieldsDataGPS(6)
        Dim CheckSum As String = FieldsDataGPS(12)

        Dim Punto As New GeoPoint
        Punto.Grabar(Mobil1, Fecha, Hora, Latitud, Longitud, Velocidad)

    End Function

End Class
